<?php

namespace app\serverexchangerate\service\Exchangerate;
use app\manage\service\ApiBase;

/**
 * @author:      李颖
 * @DateTime:    2017-09-11 17:00:58
 * @Description: 汇率
 */

class Exchangerate extends ApiBase
{
	
	protected $exchangerateLogic = 'app\serverexchangerate\logic\Exchangerate';
    protected $exchangerateValidate = 'app\serverexchangerate\validate\Exchangerate';

    /*添加一条汇率记录 注；若只传一个价格，则所有价格相同(仅适用于添加功能！)*/
    public function addRate(): array 
    {
    	$data = $this->haveIssetReceiveData(['manage_id'=>0, 'max_price'=>0, 'min_price'=>0, 'open_price'=>0, 'close_price'=>0, 'now_price'=>0]);
    	//若只传一个值，则五个值为一个价格
    	if(empty($data['max_price']) + empty($data['min_price']) + empty($data['open_price']) + empty($data['close_price']) + empty($data['now_price']) == 4){
    		$data['max_price'] = $data['min_price'] = $data['open_price'] = $data['close_price'] = $data['now_price'] = array_sum($data);
    	}
    	return $this->stepRun($data, 'addRate', '', $this->exchangerateValidate, $this->exchangerateLogic);
    }

    /*获取汇率记录列表（分页数据）*/
    public function rateList(): array 
    {
    	$data = $this->haveIssetReceiveData(['page'=>1,'listRows'=>15]);
    	return $this->stepRun($data, 'rateList', '', $this->exchangerateValidate, $this->exchangerateLogic);
    }

    /*修改其中一条记录*/
    public function updateRate(): array 
    {
    	$data = $this->issetReceiveData(['id'=>0,'manage_id'=>0, 'max_price'=>0, 'min_price'=>0, 'open_price'=>0, 'close_price'=>0, 'now_price'=>0]);
    	return $this->stepRun($data, 'updateRate', '', $this->exchangerateValidate, $this->exchangerateLogic);
    }

    /*获取最新一条汇率记录*/
    public function oneNewRate(): array 
    {
    	return $this->stepRun([], 'oneNewRate', '', $this->exchangerateValidate, $this->exchangerateLogic);
    }

    /*删除一条汇率记录*/
    public function delOneRate(): array 
    {
    	$data = $this->haveIssetReceiveData(['id'=>0]);
    	return $this->stepRun($data, 'delOneRate', '', $this->exchangerateValidate, $this->exchangerateLogic);
    }

    

}




